package com.ruoyi.project.jiaqin.intentionmessage.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.jiaqin.intentionmessage.domain.IntentionMessage;
import com.ruoyi.project.jiaqin.intentionmessage.service.IIntentionMessageService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 意向留言Controller
 * 
 * @author admin
 * @date 2021-01-05
 */
@Controller
@RequestMapping("/jiaqin/intentionmessage")
public class IntentionMessageController extends BaseController
{
    private String prefix = "jiaqin/intentionmessage";

    @Autowired
    private IIntentionMessageService intentionMessageService;

    @RequiresPermissions("jiaqin:intentionmessage:view")
    @GetMapping()
    public String intentionmessage()
    {
        return prefix + "/intentionmessage";
    }

    /**
     * 查询意向留言列表
     */
    @RequiresPermissions("jiaqin:intentionmessage:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IntentionMessage intentionMessage)
    {
        startPage();
        List<IntentionMessage> list = intentionMessageService.selectIntentionMessageList(intentionMessage);
        return getDataTable(list);
    }

    /**
     * 导出意向留言列表
     */
    @RequiresPermissions("jiaqin:intentionmessage:export")
    @Log(title = "意向留言", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IntentionMessage intentionMessage)
    {
        List<IntentionMessage> list = intentionMessageService.selectIntentionMessageList(intentionMessage);
        ExcelUtil<IntentionMessage> util = new ExcelUtil<IntentionMessage>(IntentionMessage.class);
        return util.exportExcel(list, "intentionmessage");
    }

    /**
     * 新增意向留言
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存意向留言
     */
    @RequiresPermissions("jiaqin:intentionmessage:add")
    @Log(title = "意向留言", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IntentionMessage intentionMessage)
    {
        return toAjax(intentionMessageService.insertIntentionMessage(intentionMessage));
    }

    /**
     * 修改意向留言
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        IntentionMessage intentionMessage = intentionMessageService.selectIntentionMessageById(id);
        mmap.put("intentionMessage", intentionMessage);
        return prefix + "/edit";
    }

    /**
     * 修改保存意向留言
     */
    @RequiresPermissions("jiaqin:intentionmessage:edit")
    @Log(title = "意向留言", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IntentionMessage intentionMessage)
    {
        return toAjax(intentionMessageService.updateIntentionMessage(intentionMessage));
    }

    /**
     * 删除意向留言
     */
    @RequiresPermissions("jiaqin:intentionmessage:remove")
    @Log(title = "意向留言", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(intentionMessageService.deleteIntentionMessageByIds(ids));
    }
}
